//
//  TestingCollaboration.m
//  PairTest
//
//  Created by Carlos Rodriguez Dominguez on 13/04/09.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "TestingCollaboration.h"

@implementation TestObject

-(id) initWithHandler:(EventHandler*)h
{
	[super init];
	
	x = 0;
	y = 0;
	
	handler = h;
	
	return self;
}

-(void) changeValue:(float)xx and:(float)yy
{
	x = xx;
	y = yy;
	
	PairEvent* ev = [[PairEvent alloc] initWithCommunicator:[handler communicator]];
	[ev setX:x];
	[ev setY:y];
	
	[handler push:ev];
	
	[ev release];
}

@end


@implementation TestListener

-(id) initWithController:(UIViewController*)cont
{
	if (![super init])
		return nil;
	
	controller = cont;
	
	return self;
}

-(BOOL) checkEvent:(Event*)evt
{
	if ([evt type] == PAIR_EVENT_TYPE)
		return YES;
	
	return NO;
}

-(void) action:(id)receiver event:(Event*)evt
{
	PairEvent* ev = [[PairEvent alloc] initWithEvent:evt];
	
	NSString* aux = [NSString stringWithFormat:@"%.0f, %.0f", [ev x], [ev y]];
	[[controller label] performSelectorOnMainThread:@selector(setText:) withObject:aux waitUntilDone:YES];
	
	[ev release];
}

-(NSString*) name
{
	return @"test_listener";
}

@end
